﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class LifeEvent : MonoBehaviour
{
    public float Onlose_Total=0.1f;
    public float Onlose_Speed=0.001f;
    public float Ongain_Total=0.2f;
    public float Ongain_Speed=0.002f;
    static float losetotal;
    static float losespeed;
    static float gaintotal;
    static float gainspeed;
    static float lifetotal;
    static float LifeTotal
    {
        get
        {
            return lifetotal;
        }
        set
        {
            if (value > 1)
            {
                lifetotal = 1;
            }
            else
            {
                lifetotal = value;
            }
        }
    }
    static float LifeSpeed = 0.0001f;
    public Slider slider;
    public static void OnBrickMissed()
    {
        LifeTotal -= losetotal;
        LifeSpeed += losespeed;
    }
    public static void OnBrickHit()
    {
        LifeTotal += gaintotal;
        LifeSpeed -= gainspeed;
    }
    
    void Start()
    {
        losespeed = Onlose_Speed;
        losetotal = Onlose_Total;
        gainspeed = Ongain_Speed;
        gaintotal = Ongain_Total;
        LifeSpeed = 0f;
        LifeTotal = 1;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        LifeTotal -= LifeSpeed;
        slider.value = LifeTotal;
        if (LifeTotal == 1)
        {
            LifeSpeed = 0;
        }
        if (LifeTotal <= 0)
        {
            SceneManager.LoadScene("FailedScene");
        }
    }
}
